Evolutionary Algorithms
Evolutionary algorithms are population-based search algorithms.
They do not improve one solution step-by-step like Gradient Descent. Instead, they keep many candidate solutions, let the better ones “survive”, and create new variants until a good solution appears.
Overview
Definition
Evolutionary algorithms (EA) are optimization methods inspired by biological evolution.
The basic idea is simple:
- generate many possible solutions
- score each solution by a fitness function
- keep the better solutions
- make small random changes or recombinations
- repeat the process over many generations
Imagine trying to design a good recipe without knowing the formula. You cook many versions, taste them, keep the better ones, mix ideas from them, add small experiments, and repeat. Evolutionary algorithms do this for optimization problems.
Key concepts
- Individual / candidate solution
- one possible answer to the problem
- e.g. one set of model hyperparameters, one route, one neural network architecture
- Population
- a group of candidate solutions searched at the same time
- Gene / chromosome / genome
- the representation of a solution
- e.g. a binary string, vector of real numbers, tree-shaped program, or list of choices
- Fitness function
- a scoring rule that tells us how good a solution is
- e.g. accuracy, profit, negative loss, shortest distance
- Selection
- choose better solutions to become “parents”
- Crossover / recombination
- combine parts of two or more parents
- Mutation
- randomly change a small part of a solution
- Generation
- one round of evaluate → select → create new population
General workflow
- Initialize a population randomly.
- Evaluate every candidate using the fitness function.
- Select better candidates as parents.
- Create offspring using crossover and/or mutation.
- Replace some old candidates with new ones.
- Repeat until:
- maximum generations reached
- fitness stops improving
- a good enough solution is found
graph TD
A[Random population] --> B[Evaluate fitness]
B --> C[Select good candidates]
C --> D[Create variants]
D --> E[New population]
E --> BCommon hyperparameters
- population size
- mutation rate
- crossover rate
- number of generations
- selection pressure
- elitism size
- stopping criteria
- fitness function design
Why use evolutionary algorithms
Evolutionary algorithms are useful when:
- the search space is large and messy
- the objective function is non-differentiable
- gradients are unavailable or unreliable
- there are many local optima
- the solution is discrete, symbolic, or structured
- evaluating a solution is easy, but designing the solution manually is hard
- gradient descent asks: “which direction should I move from here?”
- evolutionary algorithms ask: “among many attempts, which ones should reproduce?”
Pros & Cons
Pros
- does not require gradients
- works with discrete, continuous, and mixed search spaces
- can optimize black-box functions
- naturally parallelizable
- good for global search and messy objectives
- can handle multiple objectives
Cons
- often computationally expensive
- may need many fitness evaluations
- no guarantee of finding the global optimum
- performance depends heavily on representation and hyperparameters
- can converge too early if diversity is lost
Exploration vs. Exploitation Trade-off
Evolutionary algorithms need a balance:
- exploration: try very different solutions
- exploitation: refine already good solutions
Mutation increases exploration.
Selection increases exploitation.
Crossover can do both, depending on how it is used.
Too much exploration = random wandering.
Too much exploitation = premature convergence to a mediocre solution.
Main methods
Genetic Algorithm (GA)
Genetic algorithm is the most classic evolutionary algorithm.
It usually represents each solution as a chromosome, then uses selection, crossover, and mutation to evolve better chromosomes.
Easy intuition
GA is like breeding solutions. Good solutions are more likely to become parents, crossover mixes their useful parts, and mutation keeps the search from becoming too narrow.
How it works
- Encode each possible solution as a chromosome.
- e.g.
101101, or[learning_rate, max_depth, dropout]
- e.g.
- Generate a population of random chromosomes.
- Evaluate the fitness of each chromosome.
- Select high-fitness chromosomes as parents.
- Use crossover to exchange parts between parents.
- like taking the first half from parent A and the second half from parent B
- Use mutation to randomly change some genes.
- like flipping a bit or slightly changing a number
- The offspring form the next generation.
- Repeat until the population becomes good enough.
Evolution Strategy (ES)
Evolution strategy is often used for optimizing continuous numbers.
Instead of focusing on crossover, ES usually relies heavily on mutation and selection.
Easy intuition
ES is like standing in a foggy landscape and throwing many small stones around you. If some stones land at better places, you move toward those places and throw again.
How it works
- Start with a vector of real-valued parameters.
- e.g.
- e.g.
- Create many mutated copies by adding random noise.
- e.g.
- e.g.
- Evaluate all copies.
- Keep the best copies.
- Use them as the center for the next round of mutations.
- Repeat with gradually better parameter vectors.
Genetic Programming (GP)
Genetic programming evolves programs, not just numbers.
The solution is often represented as a tree, where nodes are operations and leaves are inputs/constants.
Easy intuition
GP is like automatically trying many little pieces of code. Useful code fragments are copied, recombined, and modified until the algorithm discovers a program that works.
How it works
- Generate many random programs.
- e.g. formulas like
x + 2,sin(x) * y, or decision rules
- e.g. formulas like
- Run each program and measure its fitness.
- Select better programs.
- Use crossover by swapping subtrees between two programs.
- Use mutation by changing an operator, variable, or subtree.
- Repeat until a useful program or formula emerges.
Differential Evolution (DE)
Differential evolution is a simple and strong method for continuous optimization.
It creates new candidate vectors by looking at the difference between existing candidates.
Easy intuition
DE asks: “how are two existing solutions different?” Then it uses that difference as a direction for trying a new solution. It learns useful step sizes from the population itself.
How it works
- Keep a population of vectors.
- For each vector, pick three other vectors:
, , and . - Create a trial vector:
where controls the mutation size. - Mix the trial vector with the original vector.
- Evaluate both.
- Keep whichever has better fitness.
Covariance Matrix Adaptation Evolution Strategy (CMA-ES)
CMA-ES is an advanced evolution strategy for continuous optimization. It learns not only where good solutions are, but also the shape and direction of the promising search region.
Easy intuition
CMA-ES is like searching with a spotlight. At first the spotlight is round and wide. As it learns where good solutions tend to be, it reshapes the spotlight into an ellipse pointing in the right direction.
How it works
- Start with a center point and a search distribution.
- Sample many candidate solutions around the center.
- Evaluate their fitness.
- Move the center toward the better candidates.
- Update the covariance matrix.
- this tells the algorithm which directions are promising
- it can stretch the search distribution along useful directions
- Repeat until convergence.
NSGA-II
NSGA-II is an evolutionary algorithm for multi-objective optimization.
It is used when there is more than one goal and the goals conflict.
Examples:
- maximize accuracy but minimize model size
- maximize profit but minimize risk
- minimize cost but maximize quality
Easy intuition
NSGA-II does not search for one “best” answer. It searches for a menu of good trade-offs, like “cheap but lower quality”, “expensive but high quality”, and several options in between.
How it works
- Generate a population of candidate solutions.
- Evaluate each solution on multiple objectives.
- Sort solutions by Pareto dominance.
- a solution is better if it improves one objective without worsening another
- Keep a diverse set of good trade-off solutions.
- Use crossover and mutation to create the next generation.
- Repeat to approximate the Pareto frontier.
Neuroevolution
Neuroevolution uses evolutionary algorithms to design or train neural networks.
It can evolve:
- neural network weights
- architectures
- activation functions
- hyperparameters
- learning rules
Easy intuition
Instead of using backpropagation to adjust one network, neuroevolution creates many networks, tests them, and lets the better designs survive.
How it works
- Represent each neural network as a genome.
- Create a population of different networks.
- Evaluate each network on a task.
- Select networks with better performance.
- Mutate or recombine their weights/structures.
- Repeat until a better network is found.
Selection methods
Fitness-proportionate selection
Also called roulette wheel selection.
Easy intuition
Better solutions get more lottery tickets, but weaker solutions can still occasionally be selected.
How it works
- each candidate gets a probability proportional to its fitness
- higher fitness means a larger slice of the wheel
- spin the wheel to select parents
Tournament selection
Easy intuition
Instead of ranking everyone globally, the algorithm runs many mini-competitions.
How it works
- Randomly choose a small group of candidates.
- Compare their fitness.
- Pick the best one as a parent.
- Repeat until enough parents are selected.
Elitism
Easy intuition
Elitism says: “before experimenting, save the best recipe we already have.”
How it works
- directly copy the best few candidates into the next generation
- this prevents the algorithm from losing the best solution found so far
Practical tips
- start with a simple representation
- design the fitness function carefully
- keep some randomness to avoid premature convergence
- use elitism to preserve the best solution
- monitor population diversity, not only best fitness
- parallelize fitness evaluation if it is expensive
- use evolutionary algorithms when gradients are not available or the search space is irregular